home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 August / Chip_2004-08_cd1.bin / oddech / hexxagon / Neave Hexxagon.exe / scripts / frame_4 / DoAction.as
Text File  |  2003-10-01  |  10KB  |  445 lines

  1. function updateGame(newPlayer)
  2. {
  3.    if(newPlayer)
  4.    {
  5.       score4 = score6 = 0;
  6.    }
  7.    var nextPlayer = player >= 5 ? 4 : 6;
  8.    var noMoves = true;
  9.    var i = 22;
  10.    while(i < 111)
  11.    {
  12.       if(newPlayer && noMoves && _root["Hexx" + i]._currentframe == nextPlayer)
  13.       {
  14.          var j = 0;
  15.          while(j < 18)
  16.          {
  17.             if(_root["Hexx" + (all[j] + i)]._currentframe == 1)
  18.             {
  19.                noMoves = false;
  20.                j = 18;
  21.             }
  22.             j++;
  23.          }
  24.       }
  25.       tellTarget("Hexx" + i)
  26.       {
  27.          if(3 < _currentframe)
  28.          {
  29.             if(_currentframe == 5 || _currentframe == 7)
  30.             {
  31.                prevFrame();
  32.             }
  33.             if(newPlayer)
  34.             {
  35.                _root["score" + _currentframe]++;
  36.                if(_root.player == 4 && !_root.compPlay)
  37.                {
  38.                   HexxButtonP1._visible = false;
  39.                   HexxButtonP2._visible = true;
  40.                }
  41.                else if(_root.player == 6)
  42.                {
  43.                   HexxButtonP1._visible = true;
  44.                   HexxButtonP2._visible = false;
  45.                }
  46.             }
  47.          }
  48.          else
  49.          {
  50.             gotoAndStop("Off");
  51.          }
  52.       }
  53.       i++;
  54.    }
  55.    if(newPlayer)
  56.    {
  57.       if(noMoves)
  58.       {
  59.          score4 = score6 = 0;
  60.          var i = 22;
  61.          while(i < 111)
  62.          {
  63.             tellTarget("Hexx" + i)
  64.             {
  65.                if(_currentframe == 1)
  66.                {
  67.                   gotoAndStop(_root.player);
  68.                }
  69.                _root["score" + _currentframe]++;
  70.                HexxButtonP1._visible = HexxButtonP2._visible = false;
  71.             }
  72.             i++;
  73.          }
  74.          if(score4 == score6)
  75.          {
  76.             Winner.gotoAndStop("Tie");
  77.          }
  78.          else if(score6 < score4)
  79.          {
  80.             Winner.gotoAndPlay("Win4");
  81.             player = 6;
  82.          }
  83.          else
  84.          {
  85.             Winner.gotoAndPlay("Win6");
  86.             player = 4;
  87.          }
  88.          Winner._visible = true;
  89.       }
  90.       var b = 4;
  91.       while(b < 8)
  92.       {
  93.          tellTarget("Bar" + b)
  94.          {
  95.             _width = _root["score" + b];
  96.             _X = 362 - _width / 2;
  97.          }
  98.          b += 2;
  99.       }
  100.       if(compAttack)
  101.       {
  102.          Bulb.play();
  103.       }
  104.       compAttack = false;
  105.       if(compPlay && !noMoves && attack && player != computer)
  106.       {
  107.          compAttack = true;
  108.       }
  109.       else
  110.       {
  111.          Turn.gotoAndStop(player / 2);
  112.          startDrag("Turn",1);
  113.       }
  114.    }
  115. }
  116. function playAnim(plyr)
  117. {
  118.    Turn.gotoAndStop(1);
  119.    stopDrag();
  120.    if(remove)
  121.    {
  122.       _root["Hexx" + unselect].gotoAndStop("Off");
  123.       remove = false;
  124.       lastHexx = hexx;
  125.    }
  126.    notRev = true;
  127.    tellTarget("P" + plyr)
  128.    {
  129.       dirn = _root.hexx - _root.unselect;
  130.       mover = _root.unselect;
  131.       if(plyr == 4 && dirn < 0)
  132.       {
  133.          mover = _root.hexx;
  134.       }
  135.       _X = _root["Hexx" + mover]._x;
  136.       _Y = _root["Hexx" + mover]._y;
  137.       var d = 0;
  138.       while(d < 6)
  139.       {
  140.          if(dirn == _root.double[d])
  141.          {
  142.             if(plyr == 6)
  143.             {
  144.                _root.Snd.gotoAndPlay("P2Double");
  145.                gotoAndPlay(7 * d + 9);
  146.             }
  147.             else
  148.             {
  149.                if(0 < dirn)
  150.                {
  151.                   gotoAndPlay(17 * d + 2);
  152.                }
  153.                else
  154.                {
  155.                   _root.notRev = false;
  156.                   gotoAndPlay(17 * d - 33);
  157.                   Rewinder.gotoAndPlay(2);
  158.                }
  159.                _root.Snd.gotoAndPlay("P1Move");
  160.             }
  161.          }
  162.          d++;
  163.       }
  164.       var d = 0;
  165.       while(d < 12)
  166.       {
  167.          if(dirn == _root.jump[d])
  168.          {
  169.             if(plyr == 6)
  170.             {
  171.                _root.animPos = 7 * d + 51;
  172.                gotoAndPlay(2);
  173.             }
  174.             else
  175.             {
  176.                if(0 < dirn)
  177.                {
  178.                   gotoAndPlay(17 * d + 53);
  179.                }
  180.                else
  181.                {
  182.                   _root.notRev = false;
  183.                   gotoAndPlay(17 * d - 33);
  184.                   Rewinder.gotoAndPlay(2);
  185.                }
  186.                _root.Snd.gotoAndPlay("P1Move");
  187.             }
  188.          }
  189.          d++;
  190.       }
  191.    }
  192.    if(compAttack)
  193.    {
  194.       Bulb.gotoAndStop(1);
  195.    }
  196. }
  197. function moveAnim(dest, plyr)
  198. {
  199.    _root["P" + plyr]._x = _root["Hexx" + dest]._x;
  200.    _root["P" + plyr]._y = _root["Hexx" + dest]._y;
  201. }
  202. function attackHexx(dest, plyr)
  203. {
  204.    _root["Hexx" + dest].gotoAndStop(plyr);
  205.    _root["P" + plyr].gotoAndStop("Zap");
  206.    var noAttack = true;
  207.    var i = 0;
  208.    while(i < 6)
  209.    {
  210.       var toZap = false;
  211.       tellTarget("Hexx" + (dest + double[i]))
  212.       {
  213.          if(3 < _currentframe && _currentframe != plyr)
  214.          {
  215.             noAttack = false;
  216.             toZap = true;
  217.             gotoAndStop(plyr);
  218.             Wobble.gotoAndStop("Morph");
  219.          }
  220.       }
  221.       _root["P" + plyr]["Zap" + double[i]]._visible = toZap;
  222.       i++;
  223.    }
  224.    if(noAttack)
  225.    {
  226.       _root["P" + plyr].gotoAndStop(1);
  227.       _root["Hexx" + dest].Wobble.gotoAndStop("Sparkle");
  228.    }
  229. }
  230. function playerSelect(hexx)
  231. {
  232.    if(compAttack || attack && player == _root["Hexx" + hexx]._currentframe)
  233.    {
  234.       return undefined;
  235.    }
  236.    _root.hexx = hexx;
  237.    attack = remove = false;
  238.    tellTarget("Hexx" + hexx)
  239.    {
  240.       if(_currentframe == 4 || _currentframe == 6)
  241.       {
  242.          _root.player = _currentframe;
  243.          _root.unselect = hexx;
  244.          nextFrame();
  245.       }
  246.       else if(_currentframe == 2)
  247.       {
  248.          _root.attack = true;
  249.          _root.lastHexx = hexx;
  250.       }
  251.       else if(_currentframe == 3)
  252.       {
  253.          _root.attack = _root.remove = true;
  254.          _root.lastHexx = hexx;
  255.       }
  256.    }
  257.    updateGame(false);
  258.    if(attack)
  259.    {
  260.       playAnim(player);
  261.    }
  262.    else
  263.    {
  264.       Snd.gotoAndPlay("Select");
  265.    }
  266.    if(lastHexx != hexx)
  267.    {
  268.       lastHexx = hexx;
  269.       _root["Hexx" + hexx].nextFrame();
  270.       var i = 0;
  271.       while(i < 6)
  272.       {
  273.          tellTarget("Hexx" + (hexx + double[i]))
  274.          {
  275.             if(_currentframe < 4)
  276.             {
  277.                gotoAndStop("Double");
  278.             }
  279.          }
  280.          tellTarget("Hexx" + (hexx + jump[i]))
  281.          {
  282.             if(_currentframe < 4)
  283.             {
  284.                gotoAndStop("Jump");
  285.             }
  286.          }
  287.          tellTarget("Hexx" + (hexx + jump[i + 6]))
  288.          {
  289.             if(_currentframe < 4)
  290.             {
  291.                gotoAndStop("Jump");
  292.             }
  293.          }
  294.          i++;
  295.       }
  296.    }
  297.    else
  298.    {
  299.       lastHexx = 0;
  300.    }
  301. }
  302. function findBestMove(compHexx)
  303. {
  304.    highestRanking = hexxOrig = hexxDest = eqCount = 0;
  305.    var check = 0;
  306.    while(check < 3)
  307.    {
  308.       var j = 0;
  309.       while(j < 6)
  310.       {
  311.          attackCount = 0;
  312.          if(check == 0)
  313.          {
  314.             hexxCheck = double[j];
  315.             if(Math.round(Math.random() * 1.5))
  316.             {
  317.                attackCount = 0.5;
  318.             }
  319.             else
  320.             {
  321.                attackCount = 1.5;
  322.             }
  323.          }
  324.          else if(check == 1)
  325.          {
  326.             hexxCheck = jump[j];
  327.          }
  328.          else if(check == 2)
  329.          {
  330.             hexxCheck = jump[j + 6];
  331.          }
  332.          var k = 0;
  333.          while(k < 6)
  334.          {
  335.             tryDest = compHexx + hexxCheck;
  336.             if(_root["Hexx" + tryDest]._currentframe == 1)
  337.             {
  338.                if(_root["Hexx" + (tryDest + double[k])]._currentframe == player)
  339.                {
  340.                   this.attackCount = this.attackCount + 1;
  341.                }
  342.             }
  343.             k++;
  344.          }
  345.          if(attackCount >= highestRanking)
  346.          {
  347.             if(_root["Hexx" + tryDest]._currentframe == 1)
  348.             {
  349.                highestRanking = attackCount;
  350.                hexxDest = tryDest;
  351.             }
  352.          }
  353.          if(attackCount == highestRanking)
  354.          {
  355.             eqCount = 0;
  356.             var k = 0;
  357.             while(k < 6)
  358.             {
  359.                if(_root["Hexx" + (compHexx + double[k])]._currentframe == computer)
  360.                {
  361.                   eqCount++;
  362.                }
  363.                else
  364.                {
  365.                   eqCount--;
  366.                }
  367.                k++;
  368.             }
  369.          }
  370.          j++;
  371.       }
  372.       check++;
  373.    }
  374.    return [highestRanking,compHexx,hexxDest,eqCount];
  375. }
  376. function computerSelect()
  377. {
  378.    thisBest = new Array(0,0,0,0);
  379.    bestMove = new Array(0,0,0,0);
  380.    var i = 22;
  381.    while(i < 111)
  382.    {
  383.       compHexx = 0;
  384.       if(_root["Hexx" + i]._currentframe == computer)
  385.       {
  386.          compHexx = i;
  387.       }
  388.       if(compHexx)
  389.       {
  390.          thisBest = findBestMove(compHexx);
  391.          if(bestMove[0] < thisBest[0])
  392.          {
  393.             bestMove = thisBest;
  394.          }
  395.          else if(thisBest[0] == bestMove[0] && thisBest[3] < bestMove[3])
  396.          {
  397.             bestMove = thisBest;
  398.          }
  399.       }
  400.       i++;
  401.    }
  402.    if(bestMove[0])
  403.    {
  404.       if(bestMove[0] - int(bestMove[0]) != 0.5)
  405.       {
  406.          remove = true;
  407.       }
  408.       unselect = bestMove[1];
  409.       hexx = bestMove[2];
  410.       player = computer;
  411.       playAnim(computer);
  412.    }
  413. }
  414. stop();
  415. Mouse.hide();
  416. double = new Array(10,11,1,-10,-11,-1);
  417. jump = new Array(9,20,21,22,12,2,-9,-20,-21,-22,-12,-2);
  418. all = jump.concat(double);
  419. attack = compAttack = remove = false;
  420. notRev = true;
  421. player = 4;
  422. computer = 6;
  423. score4 = 3;
  424. score6 = 3;
  425. unselect = 0;
  426. hexx = 0;
  427. lastHexx = 0;
  428. animPos = 1;
  429. Hexx22.gotoAndStop("On1");
  430. Hexx70.gotoAndStop("On1");
  431. Hexx106.gotoAndStop("On1");
  432. Hexx26.gotoAndStop("On2");
  433. Hexx62.gotoAndStop("On2");
  434. Hexx110.gotoAndStop("On2");
  435. Hexx26.HexxButtonP2._visible = Hexx62.HexxButtonP2._visible = Hexx110.HexxButtonP2._visible = false;
  436. var i = 1;
  437. while(i < 133)
  438. {
  439.    duplicateMovieClip("Hexx0","Hexx" + i,16384 + i);
  440.    i++;
  441. }
  442. s = new Sound();
  443. startDrag("Turn",1);
  444. Turn.gotoAndStop(3);
  445.